package com.ys.web.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.WebConstants;
import com.ys.web.pojo.CompanyInfo;
import com.ys.web.pojo.SystemPermissonInfo;
import com.ys.web.security.SystemPermissionUtils;
import com.ys.web.service.CompanyService;

public class CompanyHasBackupController {
	
	@Autowired
	CompanyService companyService;

	@RequestMapping(params = "getCompanys")
	@ResponseBody
	public List<CompanyInfo> getCompanyPage(Integer page, HttpSession session) {
		String username = (String) session.getAttribute("username");

		Integer userId = (Integer) session.getAttribute("userId");
		List<CompanyInfo> companyInfos = new ArrayList<CompanyInfo>();
		if (username != null && userId != null) {

			SystemPermissonInfo systemPermissonInfo = SystemPermissionUtils.getUserPermission(username);
			Integer infopage = 1;
			if (page != null) {
				infopage = page;
			}
		
			try {
				if (systemPermissonInfo.getRoleId().contains(WebConstants.SUPER_USER)
						|| systemPermissonInfo.getRoleId().contains(WebConstants.SEM_MANAGER_USER)) {
					// companyInfos=companyService.getCompanyBySemUserId(null,
					// infopage);
					companyInfos = companyService.getRemoteCompanyBySemUserId(null, infopage);
				} else {
					// companyInfos =
					// companyService.getCompanyBySemUserId(userId, infopage);
					companyInfos = companyService.getRemoteCompanyBySemUserId(userId, infopage);
				}

			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		return companyInfos;

	}

}
